/********************************************************************************
  * @file    verilogsyntaxhighlighter.h
  * @author  Lun Li
  * @version V1.4.0
  * @date    2022.3.23
  * @brief   This file contains all the functions prototypes for VerilogSyntaxHighlighter.
  ******************************************************************************/

#ifndef VERILOGSYNTAXHIGHLIGHTER_H
#define VERILOGSYNTAXHIGHLIGHTER_H

#include <QSyntaxHighlighter>
#include <QRegularExpression>
#include "programconfig.h"

/************
  * VerilogSyntaxHighlighter类，用于在编辑器中为verilog语法提供高亮显示
  ***********/
class VerilogSyntaxHighlighter : public QSyntaxHighlighter
{
    Q_OBJECT
public:
    VerilogSyntaxHighlighter(ProgramConfig *const config, QTextDocument *parent = nullptr);

protected:
    void highlightBlock(const QString &text) override;

private slots:
    void setColor();

private:
    struct HighlightingRule
    {
        QRegularExpression pattern;
        QTextCharFormat *format;
    };
    QList<HighlightingRule> highlightingRules;

    QRegularExpression singleLineCommentExpression;
    QRegularExpression commentStartExpression;
    QRegularExpression commentEndExpression;

    QTextCharFormat keywordFormat;
    QTextCharFormat numberFormat;
    QTextCharFormat commentFormat;
    QTextCharFormat quotationFormat;
    QTextCharFormat systemFunctionFormat;

    ProgramConfig *const m_config;
};

#endif // VERILOGSYNTAXHIGHLIGHTER_H
